//
//  LRBottomView.swift
//  LRWeibo
//
//  Created by admin on 15/9/26.
//  Copyright © 2015年 懒人. All rights reserved.
//

import UIKit

class LRBottomView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        
        // 更新UI
        setUI()
    }
    
     // MARK: - 添加UI
    private func setUI()
    {
        addSubview(retweetButton)
        addSubview(commentButton)
        addSubview(likeButton)
        let line1 = setSpline()
        let line2 = setSpline()
        addSubview(line1)
        addSubview(line2)
        
        for v in subviews
        {
            v.translatesAutoresizingMaskIntoConstraints = false
        }
        
        addConstraint(NSLayoutConstraint(item: retweetButton, attribute: .Top, relatedBy: .Equal, toItem: self, attribute: .Top, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: retweetButton, attribute: .Left, relatedBy: .Equal, toItem: self, attribute: .Left, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: retweetButton, attribute: .Bottom, relatedBy: .Equal, toItem: self, attribute: .Bottom, multiplier: 1.0, constant: 0))
        
        line1.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(0.6)
            make.width.equalTo(0.5)
            make.left.equalTo(retweetButton.snp_right)
        }
        
        addConstraint(NSLayoutConstraint(item: commentButton, attribute: .Top, relatedBy: .Equal, toItem: retweetButton, attribute: .Top, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: commentButton, attribute: .Left, relatedBy: .Equal, toItem: retweetButton, attribute: .Right, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: commentButton, attribute: .Bottom, relatedBy: .Equal, toItem: retweetButton, attribute: .Bottom, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: commentButton, attribute: .Width, relatedBy: .Equal, toItem: retweetButton, attribute: .Width, multiplier: 1.0, constant: 0))
        
        line2.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(0.6)
            make.width.equalTo(0.5)
            make.left.equalTo(commentButton.snp_right)
        }
        
        addConstraint(NSLayoutConstraint(item: likeButton, attribute: .Top, relatedBy: .Equal, toItem: commentButton, attribute: .Top, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: likeButton, attribute: .Left, relatedBy: .Equal, toItem: commentButton, attribute: .Right, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: likeButton, attribute: .Bottom, relatedBy: .Equal, toItem: commentButton, attribute: .Bottom, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: likeButton, attribute: .Width, relatedBy: .Equal, toItem: commentButton, attribute: .Width, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: likeButton, attribute: .Right, relatedBy: .Equal, toItem: self, attribute: .Right, multiplier: 1.0, constant: 0))
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
     // MARK: - 创建分割线
    private func setSpline()->UIView
    {
        let v = UIView()
        v.backgroundColor = UIColor.darkGrayColor()
        return v
    }
     // MARK: - 控件懒加载
    /// 转发
    private lazy var retweetButton: UIButton = UIButton(title: " 转发", fontSize: 12, color: UIColor.darkGrayColor(), imageName: "timeline_icon_retweet")
    /// 评论
    private lazy var commentButton: UIButton = UIButton(title: " 评论", fontSize: 12, color: UIColor.darkGrayColor(), imageName: "timeline_icon_comment")
    /// 点赞
    private lazy var likeButton: UIButton = UIButton(title: " 点赞", fontSize: 12, color: UIColor.darkGrayColor(), imageName: "timeline_icon_unlike")
}
